home *** CD-ROM | disk | FTP | other *** search
- /*
- ***********************************************************************
- *
- * Full-color (full-graw) picture items
- * (Sub)windows displaying some picture in 2D/3D
- *
- * These items are considered User Items in a dialog, and should supply
- * functions how to process hits and perform custom drawing
- *
- ***********************************************************************
- */
-
- #include "Dialog.h"
-
- class IMAGE; // Opaque class
-
-
- class ViewerPosition
- {
- public:
- int xe, ye; // Location of an observation point
- int gx, gy; // Gaze vector (of size |g|=1<<14)
- enum { g_unit = 1<<14 }; // |g|, size of the gaze vector
- ViewerPosition(const int _xe, const int _ye, const int _gx, const int _gy);
-
- void do_one_turn(void); // Perform one step of circling around
- private:
- int xc, yc; // Point to fly around
- float rx, ry; // current r = E-C, precisely!
- const float g_per_rad; // |g|/flying_radius
- enum { flying_radius = 40};
- };
-
- struct ProjectionParameters
- {
- int ze; // Elevation of the view point
- int beta; // Local coordinates scaling factor
- int Ou, Ov; // Origin of the local coordinate ref Pt
- int z_cutoff, elevation_factor; // Coefficients to determine elevation from
- // the map's "elevation code"
- };
-
- // Picture view in 2d
- class ImageView : public UserItem, public OffScreenBuffer
- {
- const IMAGE& image; // Image to view
- ViewerPosition viewer_pos; // Where the viewer is at
- public:
- ImageView(const IMAGE& image);
- void bind(const ModelessDialog& the_dialog, const int item_no); // Late constructor
- void draw(void) { OffScreenBuffer::draw(rect); draw_mark(); } // Custom-draw this item
-
- void draw_mark(void); // Draw a mark of the plane
- void undraw_mark(void); // Erase the mark of the plane
- const ViewerPosition& where_is_viewer(void) const { return viewer_pos; }
- // Perform one step of circling around
- void do_one_turn(void) { undraw_mark(); viewer_pos.do_one_turn(); draw_mark(); }
-
- enum { elevation_color_CLUT_id = 128 }; // How to colorize map pixels
- };
-
-
- // Picture view in 3d
- class ThreeDView : public UserItem, public OffScreenBuffer
- {
- const IMAGE& map; // Image to view
- const ViewerPosition& viewer_pos; // To get the view parameters from
- const ProjectionParameters& projection_parms;
-
- void project(void); // Draw a projection in an offscreen
- // world
-
- // A class to handle one scanline of the view plane
- class OneViewScanline
- {
- friend class ScanLineAccess; // needed for a member function kludge
- public:
- struct ScanPoint { // A scan point at some given u
- int v; // visible elevation (note, PowerPC prefers ints to short)
- int color; // color of a point (taken from the map)
- };
-
- OneViewScanline(const int _width);
- ~OneViewScanline(void);
-
- int q_width(void) const { return width; }
- void print(const card i=0) const; // print a scanline point
-
- private:
- const int width; // width of a scanline
- ScanPoint * const scan_points; // scanpoints of a scanline
-
- };
-
- OneViewScanline scanline1, scanline2; // Two working scanlines
-
- public:
- ThreeDView(const IMAGE& image_map, const ViewerPosition& viewer_pos,
- const ProjectionParameters& projection_parms);
- void bind(const ModelessDialog& the_dialog, const int item_no); // Late constructor
- void draw(void) { OffScreenBuffer::draw(rect); } // Custom-draw this item
- void re_project(void) { project(); draw(); }
- };
-